Skip to content

Add unit tests for SelectJdkToolchainMojo version matching - #181

Closed
elharo wants to merge 2 commits into
apache:masterfrom
elharo:add-version-matching-tests
Closed

Add unit tests for SelectJdkToolchainMojo version matching#181
elharo wants to merge 2 commits into
apache:masterfrom
elharo:add-version-matching-tests

Conversation

@elharo

@elharo elharo commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Refs #167

Adds unit tests for the matches() method in SelectJdkToolchainMojo to verify version matching behavior.

Uses reflection to test the private method without changing source code visibility. Tests confirm that RequirementMatcherFactory.createVersionMatcher() is called with the correct argument order:

  • createVersionMatcher(tcVal).matches(reqVal) where tcVal is the toolchain's concrete version and reqVal is the user's requirement (which may be a range like "[11,17)").

All 3 tests pass against the current code, confirming the existing implementation is correct.

elharo added 2 commits July 22, 2026 15:03
Fixes apache#174

The static LOCK object and synchronized block around
toolchainManagerPrivate.storeToolchainToBuildContext() are unnecessary
because:

1. The plugin is marked threadSafe=true, meaning Maven may execute it
   concurrently for different modules/sessions
2. storeToolchainToBuildContext() stores data into the build context,
   which is already per-session and thread-safe
3. The static lock introduces unnecessary contention: one module's
   toolchain selection blocks another unrelated module's selection,
   defeating the purpose of threadSafe=true

In multi-module Maven builds where the toolchains plugin runs in
multiple modules, the static lock serializes what could otherwise run
in parallel, slowing down builds.
Refs apache#167

Add tests that verify the behavior of the private matches() method
in SelectJdkToolchainMojo for the VERSION key, using reflection
to avoid changing source code visibility.

Tests confirm that RequirementMatcherFactory.createVersionMatcher()
is called with the correct argument order:
- createVersionMatcher(tcVal).matches(reqVal)
  where tcVal is the toolchain's concrete version and
  reqVal is the user's requirement (which may be a range).
@elharo elharo closed this Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant